function html_encode(str) {
	var s = "";
	if (str.length == 0)
		return "";
	s = str.replace(/&/g, "&amp;");
	s = s.replace(/</g, "&lt;");
	s = s.replace(/>/g, "&gt;");
	s = s.replace(/\'/g, "&#39;");
	s = s.replace(/\"/g, "&quot;");
	return s;
}

KE.lang['code'] = "插入程序代码或脚本";
KE.plugin['code'] = {
	click : function (id) {
		KE.util.selection(id);
		var dialog = new KE.dialog({
					id : id,
					cmd : 'code',
					file : '../../../content/plugins/syntaxHighlighter/code.html',
					width : 530,
					height : 300,
					title : KE.lang['code'],
					yesButton : KE.lang['yes'],
					noButton : KE.lang['no']
				});
		dialog.show();
	},
	check : function (id) {
		var dialogDoc = KE.util.getIframeDoc(KE.g[id].dialog);
		var lang = KE.$('ic_lang', dialogDoc).value;
		var source = KE.$('ic_source', dialogDoc).value;
		if (lang == '') {
			alert('编程语言必须选择');
			return false;
		}
		if (source == '') {
			alert('请输入程序代码或者脚本');
			return false;
		}
		return true;
	},
	exec : function (id) {
		KE.util.select(id);
		var iframeDoc = KE.g[id].iframeDoc;
		var dialogDoc = KE.util.getIframeDoc(KE.g[id].dialog);
		if (!this.check(id))
			return false;
		var lang = KE.$('ic_lang', dialogDoc).value;
		var source = KE.$('ic_source', dialogDoc).value;
		this.insert(id, lang, source);
	},
	insert : function (id, lang, source) {
		var html = '<pre class="brush:' + lang + '; toolbar: true; auto-links: true;">';
		html += html_encode(source);
		html += '</pre>';
		KE.util.insertHtml(id, html);
		KE.layout.hide(id);
		KE.util.focus(id);
		document.getElementById("codeype").value = lang;
	}
};
function loadEditor(id) {
	KE.show({
			id : id,
			resizeMode : 1,
			allowUpload : false,
			urlType : 'absolute',
			cssPath : '../../../content/plugins/syntaxHighlighter/brush/ke.css',
			items : ['code', 'bold', 'italic', 'underline', 'strikethrough', 'textcolor', 'bgcolor', 'fontname', 'fontsize', 'removeformat', 'wordpaste', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'justifyleft', 'justifycenter', 'justifyright', 'link', 'unlink', 'image', 'flash', 'advtable', 'emoticons', 'source', '|', 'about']
		});
}
 